<template>
  <view :style="themeColor">
    <view class="page">
      <view class="flex benben-position-layout flex flex-wrap align-center realNameAuthentication_flex_0"
        :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
        <view class='flex flex-wrap align-center justify-between flex-sub realNameAuthentication_fd0_0'>
          <view class='flex flex-wrap align-center realNameAuthentication_fd0_0_c0' @tap.stop="handleJumpDiy"
            data-type="back" data-url="1">
            <text class='fu-iconfont2  realNameAuthentication_fd0_0_c0_c0'>&#xE794;</text>
          </view>
          <view class='flex flex-wrap align-stretch justify-center'>
            <text class='realNameAuthentication_fd0_0_c1_c0'>{{$t('实名认证')}}</text>
          </view>
          <view class='flex flex-wrap align-center justify-end realNameAuthentication_fd0_0_c0'>
          </view>
        </view>

      </view>
      <view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
      <!---flex布局flex布局开始-->
      <view
        class="flex flex-direction flex-wrap align-center justify-center benben-flex-layout realNameAuthentication_flex_1"
        v-if="readStateNum!=0">
        <view class='flex flex-direction flex-wrap align-center justify-center' v-if="readStateNum=='1'">
          <image class='realNameAuthentication_fd1_0_c0' mode="aspectFit" :src='STATIC_URL+"518.png"'></image>
          <text class='realNameAuthentication_fd1_0_c1'>审核中，请耐心等待</text>
        </view>
        <view class='flex flex-direction flex-wrap align-center justify-center' v-if="readStateNum=='2'">
          <image class='realNameAuthentication_fd1_0_c0' mode="aspectFit" :src='STATIC_URL+"519.png"'></image>
          <text class='realNameAuthentication_fd1_0_c1'>审核未通过</text>
          <text class='realNameAuthentication_fd1_1_c2'>未通过原因：{{refuseRemark}}</text>
          <button class='realNameAuthentication_fd1_1_c3' @click.stop="submit">重新提交</button>
        </view>
        <view class='flex flex-direction flex-wrap align-center justify-center' v-if="readStateNum=='10'">
          <image class='realNameAuthentication_fd1_0_c0' mode="aspectFit" :src='STATIC_URL+"520.png"'></image>
          <text class='realNameAuthentication_fd1_0_c1'>审核通过</text>
        </view>
      </view>

      <!---flex布局flex布局结束-->
      <!---flex布局flex布局开始-->
      <view class="flex flex-direction align-stretch benben-flex-layout realNameAuthentication_flex_2">
        <view class='flex align-stretch justify-between realNameAuthentication_fd2_0'>
          <text class='realNameAuthentication_fd2_0_c0'>{{$t('真实姓名：')}}</text>
          <benben-input class='self-center realNameAuthentication_fd2_0_c1' type="text" :placeholder="$t('请输入您的真实姓名')"
            v-model="realName" confirm-type="done" :maxlength="8" placeholder-style="color:#999;font-size:28rpx" />
        </view>
        <view class='flex align-stretch justify-between realNameAuthentication_fd2_0'>
          <text class='realNameAuthentication_fd2_0_c0'>身份证号：</text>
          <benben-input class='realNameAuthentication_fd2_0_c1' type="idcard" :placeholder="$t('请输入您的身份证号码')"
            v-model="idCardNum" confirm-type="done" :maxlength="18" placeholder-style="color:#999;font-size:28rpx" />
        </view>
        <view class='flex flex-direction align-stretch realNameAuthentication_fd2_2'>
          <view class='flex flex-wrap align-center justify-between'>
            <view class='flex flex-direction flex-wrap align-stretch'>
              <text class='realNameAuthentication_fd2_2_c0_c0_c0'>{{$t('身份证国徽面')}}</text>
              <view class='flex flex-wrap align-center'>
                <view class="upload position-relative">
                  <text v-if="cardFront != ''" @tap="cardFront = ''"
                    class='fu-iconfont2 position-absolute realNameAuthentication_fd2_2_c0_c0_c1_c0_icon'>&#xE8E7;</text>
                  <image class=" realNameAuthentication_fd2_2_c0_c0_c1_c0_image" mode="aspectFill"
                    @tap="soloChooseImage('cardFront','cardFront',false,false)"
                    :src="cardFront ? cardFront : STATIC_URL+'445.png'"></image>
                </view>
              </view>
            </view>
            <view class='flex flex-direction flex-wrap align-stretch'>
              <text class='realNameAuthentication_fd2_2_c0_c0_c0'>示例</text>
              <view class='flex flex-wrap align-center'>
                <image class='realNameAuthentication_fd2_2_c0_c1_c1_c0' mode="aspectFit" :src='STATIC_URL+"508.png"'>
                </image>
              </view>
            </view>
          </view>
          <view class='flex flex-wrap align-center justify-between margin-top-sm'>
            <view class=' flex flex-direction flex-wrap align-stretch'>
              <text class='realNameAuthentication_fd2_2_c0_c0_c0'>{{$t('身份证人像面')}}</text>
              <view class='flex flex-wrap align-center'>
                <view class="upload position-relative">
                  <text v-if="cardSide != ''" @tap="cardSide = ''"
                    class='fu-iconfont2 position-absolute realNameAuthentication_fd2_2_c0_c0_c1_c0_icon'>&#xE8E7;</text>
                  <image class=" realNameAuthentication_fd2_2_c0_c0_c1_c0_image" mode="aspectFill"
                    @tap="soloChooseImage('cardSide','cardSide',false,false)"
                    :src="cardSide ? cardSide : STATIC_URL+'445.png'"></image>
                </view>
              </view>
            </view>
            <view class='flex flex-direction flex-wrap align-stretch'>
              <text class='realNameAuthentication_fd2_2_c0_c0_c0'>示例</text>
              <view class='flex flex-wrap align-center'>
                <image class='realNameAuthentication_fd2_2_c0_c1_c1_c0' mode="aspectFit" :src='STATIC_URL+"507.png"'>
                </image>
              </view>
            </view>
          </view>
        </view>
        <view v-if="readStateNum==0" class='flex flex-wrap align-center justify-center realNameAuthentication_fd2_3'
          @click.stop="submit">
          <button class='realNameAuthentication_fd2_3_c0'>{{$t('提交')}}</button>
        </view>
      </view>

      <!---flex布局flex布局结束-->


    </view>
  </view>
</template>
<script>
  import UploadImage from '@/common/utils/upload-image.js'
  import {
    validate
  } from '@/common/utils/validate.js';
  export default {
    components: {},


    data() {
      return {
        "realName": "",
        "idCardNum": "",
        "cardFront": "",
        "cardSide": "",
        readStateNum: "0", //0 未认证 1申请者 2已拒绝 10 已实名认证
        id: '',
        refuseRemark: ''
      };
    },
    computed: {
      themeColor() {
        return this.$store.getters.themeColor
      },
      isLogin() {
        return this.$store.state.token == '' ? false : true;
      },
    },
    watch: {},
    async onLoad(options) {
      //个人中心-获取会员详细信息
      if (this.isLogin === true) {
        //请求方法
        //数据验证

        let datadataMessage = await this.$api.get(global.apiUrls.getUserInfo, {

        });

        if (datadataMessage.data.code != 0) {
          this.$message.info(datadataMessage.data.msg);
          return
        }
        let infodataMessage = datadataMessage.data;
        this.readStateNum = infodataMessage.data.readStateNum
        if (this.readStateNum != 0) {
          this.getUserRealName()
        }
      }

    },
    onUnload() {

    },
    onReady() {

    },
    onShow() {

    },
    onHide() {

    },
    onResize() {

    },
    onPullDownRefresh() {

    },
    onReachBottom(e) {

    },
    onPageScroll(e) {

    },
    methods: {
      submit() {
        if (!this.realName) {
          this.$message.info('请输入姓名')
          return
        }
        if (!this.idCardNum) {
          this.$message.info('请输入身份证号')
          return
        }
        // if (!validate(this.idCardNum, 'idcard')) {
        //   this.$message.info(global.i18n.t('请输入正确的身份证'));
        //   return false;
        // }
        if (!this.cardFront) {
          this.$message.info('请上传身份证证件照')
          return
        }
        if (!this.cardSide) {
          this.$message.info('请上传身份证反面照')
          return
        }
        this.$api.dbPost(global.apiUrls.applyModUserRealName, {
          realName: this.realName,
          idCardNum: this.idCardNum,
          cardFront: this.cardFront, //身份证正面
          cardSide: this.cardSide,
          id: this.id,
        }).then(res => {
          this.$message.info(res.data.msg)
          if (res.data.code == 0) {
            setTimeout(resss => {
              uni.navigateBack()
            }, 500)
          }
        })
      },
      getUserRealName() {
        this.$api.get(global.apiUrls.getUserRealName).then(res => {
          if (res.data.code == 0) {
            this.realName = res.data.data.realName
            this.idCardNum = res.data.data.idCardNum
            this.cardFront = res.data.data.cardFront
            this.cardSide = res.data.data.cardSide
            this.refuseRemark = res.data.data.refuseRemark
            this.id = res.data.data.id
          }
        })
      },
      //上传单图、多图方法
      soloChooseImage1(id, path, obj, obj1, fnName = false) {
        let self = this
        if (!obj) obj = this
        if (!obj1) obj1 = this
        if (self.uploading) {
          return
        }
        uni.chooseImage({
          count: 1, // 默认3
          sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
          success: function(res) {
            self.uploading = true
            // 开始上传
            new UploadImage(res.tempFiles, {
              complete: function(res) {
                self.uploading = false
                if (id == 'cardFront') {
                  self.cardFront = res[0]
                } else {
                  self.cardSide = res[0]
                }
              },
            })
          },
        })
      },
      //上传单图、多图方法
      soloChooseImage(id, path, obj, obj1, fnName = false) {
        let platform = uni.getSystemInfoSync().platform
        if (platform == 'ios') {
          this.soloChooseImage1(id, path, obj, obj1, fnName = false)
          return
        }
        let self = this
        if (!obj) obj = this
        if (!obj1) obj1 = this
        if (self.uploading) {
          return
        }
        uni.showModal({
          title: '相机相册信息授权提示',
          content: '用户拍摄/选取内容发布，拍摄/选取图片更换头像，扫描二维码，聊天功能，提交意见反馈或者AR识别等功能？',
          success(res1) {
            if (res1.confirm) {
              // 从相册中选择图片
              uni.chooseImage({
                count: 1, // 默认3
                sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
                success: function(res) {
                  self.uploading = true
                  // 开始上传
                  new UploadImage(res.tempFiles, {
                    complete: function(res) {
                      self.uploading = false
                      if (id == 'cardFront') {
                        self.cardFront = res[0]
                      } else {
                        self.cardSide = res[0]
                      }
                    },
                  })
                },
              })
            } else if (res1.cancel) {
              console.log('用户点击取消');
            }
          }
        })
      }
    }
  };
</script>
<style lang="scss" scoped>
  .page {
    width: 100vw;
    overflow-x: hidden;
    min-height: calc(100vh - var(--window-bottom));
    background: #F8F8F8;
    background-size: 100% auto;
  }

  .realNameAuthentication_flex_0 {
    border-bottom: 1px solid #eee;
    background: #fff;
    width: 750rpx;
    height: 88rpx;
    overflow: hidden;
    z-index: 10;
    top: 0rpx;
    background-size: 100% auto !important;
  }

  .realNameAuthentication_fd0_0_c1_c0 {
    font-size: 36rpx;
    font-weight: 700;
    color: #333;
    line-height: 88rpx;
  }

  .realNameAuthentication_fd0_0_c0_c0 {
    font-size: 36rpx;
    color: #333;
  }

  .realNameAuthentication_fd0_0_c0 {
    width: 120rpx;
  }

  .realNameAuthentication_fd0_0 {
    padding: 0rpx 32rpx 0rpx 32rpx;
  }

  .realNameAuthentication_flex_1 {
    background: var(--benbenbgColor1);
    background-size: 100% auto;
    width: 710rpx;
    margin: 24rpx auto 0rpx auto;
    border-radius: 16rpx;
    padding: 32rpx 0rpx 32rpx 0rpx;
  }

  .realNameAuthentication_fd1_1_c3 {
    background: #4781f5;
    border-radius: 33rpx 33rpx 33rpx 33rpx;
    width: 202rpx;
    line-height: 68rpx;
    font-size: 32rpx;
    color: #fff;
  }

  .realNameAuthentication_fd1_1_c2 {
    font-size: 24rpx;
    margin: 12rpx 0rpx 32rpx 0rpx;
    color: rgba(119, 119, 119, 1);
  }

  .realNameAuthentication_fd1_0_c1 {
    margin: 24rpx 0rpx 0rpx 0rpx;
  }

  .realNameAuthentication_fd1_0_c0 {
    width: 80rpx;
    height: 80rpx;
  }

  .realNameAuthentication_flex_2 {
    background: var(--benbenbgColor1);
    margin: 20rpx auto 20rpx auto;
    width: 710rpx;
    background-size: 100% auto;
    border-radius: 16rpx;
    padding: 0rpx 24rpx 0rpx 24rpx;
  }

  .realNameAuthentication_fd2_3_c0 {
    background: var(--benbenbgColor7);
    border-radius: 44rpx 44rpx 44rpx 44rpx;
    width: 686rpx;
    line-height: 88rpx;
    font-size: 32rpx;
    color: #fff;
    height: 88rpx;
  }

  .realNameAuthentication_fd2_3 {
    position: fixed;
    left: 0rpx;
    bottom: calc(48rpx + var(--window-bottom));
    width: 750rpx;
  }

  .realNameAuthentication_fd2_2_c0_c1_c1_c0 {
    width: 316rpx;
    height: 204rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
  }

  .realNameAuthentication_fd2_2_c0_c0_c1_c0_image {
    width: 314rpx;
    height: 204rpx;
    border-radius: 8rpx;
  }

  .realNameAuthentication_fd2_2_c0_c0_c1_c0_icon {
    top: 0rpx;
    right: 0rpx;
    z-index: 1;
    color: #ff5536;
  }

  .realNameAuthentication_fd2_2_c0_c0_c0 {
    color: #333333;
    font-size: 32rpx;
    font-weight: 500;
    line-height: 45rpx;
    margin: 0rpx 0rpx 32rpx 0rpx;
  }

  .realNameAuthentication_fd2_2 {
    padding: 48rpx 0rpx 0rpx 0rpx;
  }

  .realNameAuthentication_fd2_0_c1 {
    text-align: right;
  }

  .realNameAuthentication_fd2_0_c0 {
    color: #333333;
    font-size: 28rpx;
    font-weight: 500;
    line-height: 40rpx;
    margin: 0rpx 0rpx 20rpx 0rpx;
  }

  .realNameAuthentication_fd2_0 {
    border-bottom: 1px solid #eee;
    padding: 24rpx 0rpx 24rpx 0rpx;
  }
</style>
